package com.mcppro.aidatabase.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

/**
 * 聊天接口请求响应DTO
 * 
 * @author MCP Pro
 */
public class ChatDto {

    /**
     * 聊天请求DTO
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ChatRequest {
        
        /**
         * 会话ID
         */
        private String sessionId;
        
        /**
         * 用户问题
         */
        @NotBlank(message = "用户问题不能为空")
        @Size(max = 2000, message = "问题长度不能超过2000字符")
        private String question;
        
        /**
         * 是否需要详细解析信息
         */
        private boolean includeDetails = false;
    }

    /**
     * 聊天响应DTO
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ChatResponse {
        
        /**
         * 响应是否成功
         */
        private boolean success;
        
        /**
         * AI回复消息
         */
        private String message;
        
        /**
         * 数据库查询结果
         */
        private DatabaseOperationResult databaseResult;
        
        /**
         * 意图解析结果（仅在includeDetails=true时返回）
         */
        private IntentDto.IntentResult intentResult;
        
        /**
         * 错误信息
         */
        private String errorMessage;
        
        /**
         * 会话ID
         */
        private String sessionId;
        
        /**
         * 响应时间戳
         */
        private Long timestamp;
        
        /**
         * 总执行时间（毫秒）
         */
        private Long totalExecutionTime;

        /**
         * 创建成功响应
         */
        public static ChatResponse success(String message, DatabaseOperationResult dbResult, String sessionId) {
            ChatResponse response = new ChatResponse();
            response.setSuccess(true);
            response.setMessage(message);
            response.setDatabaseResult(dbResult);
            response.setSessionId(sessionId);
            response.setTimestamp(System.currentTimeMillis());
            return response;
        }

        /**
         * 创建失败响应
         */
        public static ChatResponse failure(String errorMessage, String sessionId) {
            ChatResponse response = new ChatResponse();
            response.setSuccess(false);
            response.setErrorMessage(errorMessage);
            response.setSessionId(sessionId);
            response.setTimestamp(System.currentTimeMillis());
            return response;
        }
    }
}